/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package pa165.pneu.pneuservisbackend.services;

import java.util.ArrayList;
import java.util.List;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import pa165.pneu.pneuservisbackend.dao.ServicePneuDAO;
import pa165.pneu.pneuservisbackend.entiies.ServicePneu;
import pa165.pneu.pneuservisbackend.to.ServicePneuTO;

/**
 *
 * @author Lukas Valkovic
 */
@Service
public class ServicePneuServiceImpl implements ServicePneuService {

    @Autowired
    private ServicePneuDAO servicePneuDAO;

    @Transactional
    @Override
    public void createService(ServicePneuTO servicePneu) {
        servicePneuDAO.createService(servicePneu.toServicePneu());
    }

    @Transactional
    @Override
    public ServicePneuTO getService(Long id) {
        return new ServicePneuTO(servicePneuDAO.getService(id));
    }
    
    @Transactional
    @Override
    public void updateService(ServicePneuTO servicePneu) {
        servicePneuDAO.updateService(servicePneu.toServicePneu());
    }

    @Transactional
    @Override
    public void removeService(ServicePneuTO servicePneu) {
        servicePneuDAO.removeService(servicePneu.toServicePneu());
    }

    @Transactional
    @Override
    public List<ServicePneuTO> getAllServices() {
        List<ServicePneuTO> result = new ArrayList<>();
        for (ServicePneu s : servicePneuDAO.getAllServices()) {
            result.add(new ServicePneuTO(s));
        }
        return result;
    }

    @Transactional
    @Override
    public List<ServicePneuTO> findServiceWithName(String name) {
        List<ServicePneuTO> result = new ArrayList<>();
        for (ServicePneu s : servicePneuDAO.findServiceWithName(name)) {
            result.add(new ServicePneuTO(s));
        }
        return result;
    }
}
